﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestFYP
{
    class StyleChecker
    {
        private Counters expectedStyle,observedStyle;
        private List<Counters> compareList;
        private const Double chiVal = 80.23209774;
        private Double[] observed = new Double[11];
        private Double[] expected = new Double[11];
        private Double[] ch = new Double[11];
        
        public StyleChecker(List<Counters> compareList)
        {
            this.compareList = compareList;
        }

        public void CheckStyles() 
        {
            setMainStyle();
            
            expectedStyle.setTotal();
            Console.WriteLine("total: " + expectedStyle.Total.ToString());
            expected[0] = expectedStyle.punc_CloseBracket / expectedStyle.WordCount;
            expected[1] = expectedStyle.punc_colon / expectedStyle.WordCount;
            expected[2] = expectedStyle.punc_comma / expectedStyle.WordCount;
            expected[3] = expectedStyle.punc_exclamation / expectedStyle.WordCount;
            expected[4] = expectedStyle.punc_invertcomma / expectedStyle.WordCount;
            expected[5] = expectedStyle.punc_OpenBracket / expectedStyle.WordCount;
            expected[6] = expectedStyle.punc_period / expectedStyle.WordCount;
            expected[7] = expectedStyle.punc_question / expectedStyle.WordCount;
            expected[8] = expectedStyle.punc_semicolon / expectedStyle.WordCount;
            expected[9] = expected.Sum();

            foreach (Counters counter in compareList)
            {
                observedStyle = counter;
                for (int i = 0; i < 10; i++) 
                {
                    observed[i] = 0;
                }

                observedStyle.setTotal();
                compareStyles();
            }
        }

        private void setMainStyle() 
        {
            //if (mainStyle.Equals(null))
            expectedStyle = compareList.ElementAt(1);
            
        }

        private void compareStyles() 
        {

            observed[0] = 100 * observedStyle.punc_CloseBracket / observedStyle.WordCount;
            observed[1] = 100 * observedStyle.punc_colon / observedStyle.WordCount;
            observed[2] = 100 * observedStyle.punc_comma / observedStyle.WordCount;
            observed[3] = 100 * observedStyle.punc_exclamation / observedStyle.WordCount;
            observed[4] = 100 * observedStyle.punc_invertcomma / observedStyle.WordCount;
            observed[5] = 100 * observedStyle.punc_OpenBracket / observedStyle.WordCount;
            observed[6] = 100 * observedStyle.punc_period / observedStyle.WordCount;
            observed[7] = 100 * observedStyle.punc_question / observedStyle.WordCount;
            observed[8] = 100 * observedStyle.punc_semicolon / observedStyle.WordCount;
            observed[9] = observed.Sum();


            for (int i = 0; i < 10; i++)
            {
                ch[i] = Math.Pow((observed[i] - expected[i]),2) / expected[i];
            }

            for (int i = 0; i < 10; i++) 
            {
                Console.WriteLine("Observing "+ observed[i].ToString());
                Console.WriteLine("Expecting "+ expected[i].ToString());
            }

            Console.WriteLine(observedStyle.title + ": " + ch.Sum().ToString());    
            //Console.WriteLine(observedStyle.title + ": " + ch.ToString());
           // Console.WriteLine("total2: " + mainStyle.Total.ToString());
        }
    }
}
